<a href="http://github.com/angular/angular.js/tree/v1.2.2/src/ng/filter.js#L3" class="view-source btn btn-action"><i class="icon-zoom-in"> </i> View source</a><a href="http://github.com/angular/angular.js/edit/master/src/ng/filter.js" class="improve-docs btn btn-primary"><i class="icon-edit"> </i> Improve this doc</a><h1><code ng:non-bindable="">$filterProvider</code>
<div><span class="hint">service in module <code ng:non-bindable="">ng</code>
</span>
</div>
</h1>
<div><h2 id="description">Description</h2>
<div class="description"><div class="ng-filterprovider-page"><p>Filters are just functions which transform input to an output. However filters need to be
Dependency Injected. To achieve this a filter definition consists of a factory function which is
annotated with dependencies and is responsible for creating a filter function.</p>
<pre class="prettyprint linenums">
  // Filter registration
  function MyModule($provide, $filterProvider) {
    // create a service to demonstrate injection (not always needed)
    $provide.value('greet', function(name){
      return 'Hello ' + name + '!';
    });

    // register a filter factory which uses the
    // greet service to demonstrate DI.
    $filterProvider.register('greet', function(greet){
      // return the filter function which uses the greet service
      // to generate salutation
      return function(text) {
        // filters need to be forgiving so check input validity
        return text && greet(text) || text;
      };
    });
  }
</pre>
<p>The filter function is registered with the <code>$injector</code> under the filter name suffix with
<code>Filter</code>.</p>
<pre class="prettyprint linenums">
  it('should be the same instance', inject(
    function($filterProvider) {
      $filterProvider.register('reverse', function(){
        return ...;
      });
    },
    function($filter, reverseFilter) {
      expect($filter('reverse')).toBe(reverseFilter);
    });
</pre>
<p>For more information about how angular filters work, and how to create your own filters, see
<a href="guide/filter">Filters</a> in the Angular Developer Guide.</p>
</div></div>
<div class="member method"><h2 id="methods">Methods</h2>
<ul class="methods"><li><h3 id="methods_register">register(name, fn)</h3>
<div class="register"><div class="ng-filterprovider-register-page"><p>Register filter factory function.</p>
</div><h5 id="methods_register_parameters">Parameters</h5><table class="variables-matrix table table-bordered table-striped"><thead><tr><th>Param</th><th>Type</th><th>Details</th></tr></thead><tbody><tr><td>name</td><td><a href="" class="label type-hint type-hint-string">String</a></td><td><div class="ng-filterprovider-register-page"><p>Name of the filter.</p>
</div></td></tr><tr><td>fn</td><td><a href="" class="label type-hint type-hint-function">function</a></td><td><div class="ng-filterprovider-register-page"><p>The filter factory function which is injectable.</p>
</div></td></tr></tbody></table></div>
</li>
</ul>
</div>
</div>
